#pragma once
#include"HashTable.h"

template<class K, class V, class HashFun = Hash<K>>
class unorder_map
{

	struct MapKeyOfT
	{
		const K& operator()(const pair<K, V>& kv)
		{
			return kv.first;
		}
	};

public:
	typedef typename LinkHash::HashTable<K, pair<K, V>, MapKeyOfT, HashFun>::iterator iterator;
	typedef typename LinkHash::HashTable<K, pair<K, V>, MapKeyOfT, HashFun>::const_iterator const_iterator;

	iterator begin()
	{
		return _hs.begin();
	}

	iterator end()
	{
		return _hs.end();
	}

	V& operator[](const K& key)
	{
		pair<iterator, bool> ret = _hs.Insert(make_pair(key, V()));
		return ret.first->second;
	}

	pair<iterator, bool> insert(const pair<K, V>& kv)
	{
		return _hs.Insert(kv);
	}

private:
	LinkHash::HashTable<K, pair<K, V>, MapKeyOfT, HashFun> _hs;
};

void map_test()
{
	unorder_map<int, string> hs;
	auto ret1 = hs.insert(make_pair(1, "one"));
	hs.insert(make_pair(2, "two"));
	hs.insert(make_pair(3, "tree"));
	hs.insert(make_pair(11, "four"));
	hs.insert(make_pair(12, "four"));
	hs.insert(make_pair(13, "four"));
	hs.insert(make_pair(21, "four"));
	hs.insert(make_pair(22, "four"));
	hs.insert(make_pair(23, "four"));
	hs.insert(make_pair(31, "four"));
	hs.insert(make_pair(32, "four"));
	hs.insert(make_pair(33, "four"));
	hs.insert(make_pair(41, "four"));
	hs.insert(make_pair(4, "four"));
	hs.insert(make_pair(4, "four"));
	hs.insert(make_pair(4, "four"));
	hs.insert(make_pair(4, "four"));
	hs[11] = "eleven";
	auto ret = hs.begin();
	while (ret != hs.end())
	{
		cout << (*ret).first << "--->" << ret->second << " ";
		++ret;
	}
	cout << endl;

	cout << hs[11];
	cout << endl;
	cout << hs[14];
}d